<template>
  <div class="login-container">
    <van-nav-bar class="my-nav-bar" title="登录" />
    <van-form @submit="onSubmit">
      <van-field
        v-model="mobile"
        name="mobile"
        placeholder="请输入手机号"
        left-icon="music-o"
      >
        <i slot="left-icon" class="toutiao toutiao-shouji"></i
      ></van-field>
      <van-field
        v-model="code"
        name="code"
        placeholder="请输入验证码"
        left-icon="music-o"
      >
        <i slot="left-icon" class="toutiao toutiao-yanzhengma"></i>
        <template #button>
          <van-button size="small" type="default">发送验证码</van-button>
        </template>
      </van-field>
      <div class="login-btn-wrap">
        <van-button
          block
          type="info"
          native-type="submit"
          :loading="isLoading"
          loading-text="登录中..."
          :disabled="isDisabled"
          >登录</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { userLogin } from '../../api/user'
import { saveToken } from '../../utils/token'
export default {
  name: 'login',
  components: {},
  props: {},
  data () {
    return {
      mobile: '18888888888',
      code: '',
      isLoading: false,
      isDisabled: false
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onSubmit (value) {
      this.isLoading = true
      this.isDisabled = true
      userLogin(value)
        .then(res => {
          this.isLoading = false
          this.isDisabled = false

          console.log('res', res)
          // 本地存储token
          saveToken(res.data.data)
          this.$toast.success('登录成功')
        })
        .catch(err => {
          console.log(err)
          this.$toast.fail('登录失败')
        })
    }
  }
}
</script>

<style lang="less">
.login-container {
  .my-nav-bar.van-nav-bar {
    background-color: #3296fa;
    .van-nav-bar__title {
      color: #fff;
    }
  }
  .login-btn-wrap {
    padding: 52px 28px;
    .van-button {
      background-color: #6db4fb;
    }
  }
  .toutiao {
    width: 24px;
    height: 37px;
  }
  .van-button--default {
    background-color: #ededed;
  }
}
</style>
